//
// Created by lenovo on 2024/7/2.
//
#include "./GameObj.h"
namespace Game::Obj{
//    CollisionManager cManager ;

#ifdef CMANAGER
    CollisionManager& CollisionManager::getInstance() {
        static CollisionManager instance;
        return instance;
    }

    std::vector<Bullet*> CollisionManager::bullets;
    std::vector<Player*> CollisionManager::players;

    void CollisionManager::registe(Game::Obj::GameObj *obj) {
        if (Player* p = dynamic_cast<Player*> (obj)){
            players.push_back(p);
        }
        else if (Bullet* b = dynamic_cast<Bullet*>(obj)){
            bullets.push_back(b);
        }
    }

    void CollisionManager::checkCollision() {
        cout << "bullets num " << bullets.size() << endl ;
        for (auto bullet : bullets){
            for (auto player : players){
                if (bullet->collider->intersect(*player->collider)){
                    bullet->onCollision(player);
                    player->onCollision(bullet);
                }
            }
        }
    }
#endif
}